package com.korion.learn.andriod_rust

import android.os.Bundle
import android.util.Log
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import java.io.File
import kotlin.system.exitProcess

class MainActivity : AppCompatActivity() {
    companion object {
        private const val TAG = "MainActivity"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val dir = this.getExternalFilesDir(null);
        val path = dir?.absolutePath+"/default_%Nm_%p.profraw"
//        System.setProperty("LLVM_PROFILE_FILE", path);
        Log.d(TAG, "LLVM_PROFILE_FILE: $path")
        android.system.Os.setenv("LLVM_PROFILE_FILE", path, true);

        findViewById<Button>(R.id.btn_start).setOnClickListener {
            Log.d(TAG, "jni generate: ${JNIBridge.gen_random_num()}")
        }

        findViewById<Button>(R.id.btn_exit).setOnClickListener {
//            exitProcess(0)
//            finish()
            JNIBridge.dump_coverage(path)
        }
    }

}